//
//  LoginMainViewController.m
//  OAProject
//
//  Created by yhj on 2017/7/10.
//  Copyright © 2017年 cdnunion. All rights reserved.
//  登录主界面

#import "LoginMainViewController.h"
#import "RegisterViewController.h"
#import "ForgetPaswordViewController.h"

@implementation LoginMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.title=@"登录";

    [self loginByPhonePassword];

    [AppUI initNavigationItem:self.navigationItem andWithText:@"忘记密码" andTextColor:WhiteColor andIsRight:YES withBlock:^{

        ForgetPaswordViewController *vc=[ForgetPaswordViewController new];
        [self.navigationController pushViewController:vc animated:NO];
    }];

    [self loginByQQWechat];
    
}

-(void)loginByQQWechat
{
    UILabel *label=[self.view getLabelWithText:@"使用社交账号登录" font:FontNumber(14) textColor:MainColor textAlignment:1 lineBreakMode:NSLineBreakByTruncatingTail numberOfLines:1];
    label.frame=CGRectMake(APPW/4,APPH*3/4,APPW/2,30);
    [self.view addSubview:label];

    UIView *lineView1=[UIView new];
    lineView1.backgroundColor=MainColor;
    [self.view addSubview:lineView1];
    [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(kmargin*2);
        make.right.mas_equalTo(label.mas_left).offset(-kmargin);
        make.centerY.mas_equalTo(label.mas_centerY);
        make.height.mas_equalTo(1);
    }];

    UIView *lineView2=[UIView new];
    lineView2.backgroundColor=MainColor;
    [self.view addSubview:lineView2];
    [lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-kmargin*2);
        make.left.mas_equalTo(label.mas_right).offset(kmargin);
        make.centerY.mas_equalTo(label.mas_centerY);
        make.height.mas_equalTo(1);
    }];

    NSArray *titleArr=@[@"QQ登录",@"微信登录"];
    NSArray *imageArr=@[@"place",@"place"];
    for (NSInteger i=0;i<2;i++)
    {
        RTIconButton *QQWechatBtn=[RTIconButton new];
        QQWechatBtn.frame=CGRectMake(APPW/5+(i%2)*APPW*2/5,CGRectGetMaxY(label.frame)+kmargin,APPW/5,APPW/5);
        [QQWechatBtn setTitle:titleArr[i] forState:0];
        [QQWechatBtn setImage:[UIImage imageNamed:imageArr[i]] forState:0];
        [QQWechatBtn setTitleColor:LightGreyColor forState:0];
        QQWechatBtn.iconPosition=RTIconPositionTop;
        QQWechatBtn.tag=4000+i;
        QQWechatBtn.backgroundColor=MainColor;
        QQWechatBtn.iconMargin=kmargin;
        QQWechatBtn.titleLabel.font=FontNumber(14);
        [self.view addSubview:QQWechatBtn];
        [QQWechatBtn addTarget:self action:@selector(QQWechatBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
    }
}


-(void)QQWechatBtnEvent:(RTIconButton *)sender
{
    if (sender.tag==4000)
    {
        [self.view makeToast:@"QQ登录" duration:1 position:CSToastPositionCenter];
    }
    else if (sender.tag==4001)
    {
         [self.view makeToast:@"微信登录" duration:1 position:CSToastPositionCenter];
    }
}


-(void)loginByPhonePassword
{
    UIView *bgView=[[UIView alloc]initWithFrame:CGRectMake(0,74,APPW,50*2)];
    bgView.backgroundColor=WhiteColor;
    [self.view addSubview:bgView];

    NSArray *placeholderArr=@[@"登录手机号",@"密码"];
    for (NSInteger i=0;i<2;i++)
    {
        UITextField *textTF=[[UITextField alloc]initWithFrame:CGRectMake(kmargin*2,(i%2)*50,APPW-kmargin*4,50)];
        textTF.placeholder=placeholderArr[i];
        textTF.tag=3000+i;
        textTF.textColor=LightGreyColor;
        [bgView addSubview:textTF];

        UIView *lineView=[[UIView alloc]initWithFrame:CGRectMake(kmargin*2,49,APPW,1)];
        lineView.backgroundColor=LightGreyColor;
        [bgView addSubview:lineView];
    }

    UIButton *loginBtn=[AppUI createButtonWithText:@"登    录" andWithTextColor:WhiteColor andWithFontfloat:18 andWithBtnAction:^{
        [self loginSubmitService];
    }];
    loginBtn.backgroundColor=MainColor;
    ViewBorderRadius(loginBtn,kmargin,1,ClearColor);
    [self.view addSubview:loginBtn];
    loginBtn.frame=CGRectMake(kmargin*2,CGRectGetMaxY(bgView.frame)+kmargin*2,APPW-kmargin*4,kmargin*4);


    UIButton *registerBtn=[AppUI createButtonWithText:@"立即注册" andWithTextColor:MainColor andWithFontfloat:18 andWithBtnAction:^{
        RegisterViewController *vc=[RegisterViewController new];
        [self.navigationController pushViewController:vc animated:NO];
    }];
    registerBtn.backgroundColor=WhiteColor;
    ViewBorderRadius(registerBtn,kmargin,1,MainColor);
    [self.view addSubview:registerBtn];
    registerBtn.frame=CGRectMake(kmargin*2,CGRectGetMaxY(loginBtn.frame)+kmargin*2,APPW-kmargin*4,kmargin*4);
}


-(void)loginSubmitService
{
    UITextField *phoneTF=(UITextField *)[self.view viewWithTag:3000];
    UITextField *passwordTF=(UITextField *)[self.view viewWithTag:3001];
    if (phoneTF.text.length==0)
    {
        [self.view makeToast:@"请输入手机号" duration:1 position:CSToastPositionCenter];
    }
    else if (passwordTF.text.length==0)
    {
       [self.view makeToast:@"请输入密码" duration:1 position:CSToastPositionCenter];
    }
    else
    {

    }
}


@end
